import fs from 'fs'
import Koa from 'koa'
import Router from 'koa-router'

// const Router = new Router()

type RouterFile = {
  default: Router<any, {}>
}

const useRoutes = (app: Koa) => {
  fs.readdirSync(__dirname).forEach((file) => {
    if (file.indexOf('index') === 0) return

    import(`./${file}`)
      .then((res: RouterFile) => {
        const r = res.default
        //  router.use(r.routes)
        // console.log(r)
        app.use(r.routes())
      })
      .catch((e) => {
        console.error(e)
      })
  })
}
export default useRoutes
